//
//  AnjiaCustomAnnotationView.m
//  flutter_bmfmap
//
//  Created by Akey on 2020/11/13.
//

#import "AnjiaCustomAnnotationView.h"

@interface AnjiaCustomAnnotationView ()

/// 选中图片
@property(nonatomic, strong) UIImageView *selectImageView;
/// 
@property(nonatomic, strong) UILabel *textTop;
///
@property(nonatomic, strong) UILabel *textBottom;

@end

@implementation AnjiaCustomAnnotationView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}

- (void)createUI {
    self.hidden = YES;
    [self addSubview:self.selectImageView];
    [self addSubview:self.textTop];
    [self addSubview:self.textBottom];
//    self.transform = CGAffineTransformMakeScale(0,0);
}

- (void)showAnimation {
    self.hidden = NO;
    [UIView animateWithDuration:0.3 animations:^{
        self.transform = CGAffineTransformIdentity;
    }];
}

- (void)setOptions:(BMFAnnotationViewOptions *)options {
    _options = options;
    self.selectImageView.image = options.selectedType == 1 ? [UIImage imageNamed:@"椭圆-选中"] : [UIImage imageNamed:@"椭圆4拷贝9"];
    self.textTop.text = options.title;
    self.textBottom.text = options.subtitle;
    [self showAnimation];
}

- (UIImageView *)selectImageView {
    if (!_selectImageView) {
        _selectImageView = [UIImageView new];
        _selectImageView.frame = CGRectMake(0, 0, 96, 96);
    }
    return _selectImageView;
}

- (UILabel *)textTop {
    if (!_textTop) {
        _textTop = [UILabel new];
        _textTop.textColor = [UIColor whiteColor];
        _textTop.font = [UIFont systemFontOfSize:12];
        _textTop.frame = CGRectMake(15, 32, 66, 14);
        _textTop.textAlignment = NSTextAlignmentCenter;
    }
    return _textTop;
}

- (UILabel *)textBottom {
    if (!_textBottom) {
        _textBottom = [UILabel new];
        _textBottom.textColor = [UIColor whiteColor];
        _textBottom.font = [UIFont systemFontOfSize:12];
        _textBottom.frame = CGRectMake(15, self.textTop.frame.origin.y + 14 + 7, 66, 14);
        _textBottom.textAlignment = NSTextAlignmentCenter;

    }
    return _textBottom;
}

@end
